﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using University.Workshop.Model;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for ProductManagerTest and is intended
    ///to contain all ProductManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ProductManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for LoadNBuyProduct
        ///</summary>
        [TestMethod()]
        public void LoadNBuyProductTest()
        {
            int expected = 0; // TODO: Initialize to an appropriate value
            int actual;
            actual = ProductManager.LoadNBuyProduct();
            //Assert.AreEqual(expected, actual);  
            Assert.AreNotEqual(expected, actual);
        }

        /// <summary>
        ///A test for LoadDataGridProduct
        ///</summary>
        [TestMethod()]
        public void LoadDataGridProductTest()
        {
            DataTable actual;
            actual = ProductManager.LoadDataGridBuy();
            Assert.IsTrue(actual.Rows.Count>=0);
        }

        /// <summary>
        ///A test for LoadNameProduct
        ///</summary>
        [TestMethod()]
        public void LoadNameProductTest()
        {
            string product = "Jeringa"; // TODO: Initialize to an appropriate value
            string expected = "2023"; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadNameProduct(product);
            Assert.AreEqual(expected, actual.Rows[0]["IdProduct"].ToString());
        }

        /// <summary>
        ///A test for LoadProduct
        ///</summary>
        [TestMethod()]
        public void LoadProductTest()
        {
            string product = "Anestesia"; // TODO: Initialize to an appropriate value
            string expected = "Jeringa"; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadProduct(product);
            Assert.AreEqual(expected, actual.Rows[0]["NameProduct"].ToString());
        }
        private Product LoadProduct()
        {
            Product product = new Product();
            Random random = new Random(DateTime.Today.Millisecond);
            product.IdProduct = 13 + random.Next(1000); 
            product.GroupProduct = "Cirucia Bucal";
            product.NameProduct = "Gasas";
            product.StockCurrent=15;
            return product;
        }
        private ProductBuy LoadBuy(int codeProduct) 
        {
            ProductBuy buy = new ProductBuy();
            buy.IdProduct = codeProduct;
            buy.CIManager = "6600234";
            buy.DateBuy = DateTime.Today.ToShortDateString();
            buy.Supplier= "Depositos dentales";
            buy.StockOrder = 20;
            buy.UnitPrice = 2;
            buy.TotalPrice = 20 * 2;
            buy.Description = "Test";
            return buy;
        }
        /// <summary>
        ///A test for null NewProductRegister
        ///</summary>
        [TestMethod()]
        public void NewProductRegisterNullTest()
        {
            Product product = null; // TODO: Initialize to an appropriate value
            ProductBuy buy = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = ProductManager.NewProductRegister(product, buy);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///A test for NewProductRegister
        ///</summary>
        [TestMethod()]
        public void NewProductRegisterTest()
        {
            Product product = LoadProduct(); // TODO: Initialize to an appropriate value
            int codeProduct = product.IdProduct;
            ProductBuy buy = LoadBuy(codeProduct); // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = ProductManager.NewProductRegister(product, buy);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///A test for Update NewProductRegister
        ///</summary>
        [TestMethod()]
        public void NewProductRegisterUpdateTest()
        {
            Product product = LoadProduct(); // TODO: Initialize to an appropriate value
            int codeProduct = product.IdProduct;
            product.NameProduct = "Jeringa";
            ProductBuy buy = LoadBuy(codeProduct); // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = ProductManager.NewProductRegister(product, buy);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///A test for codeProduct LoadDataGridViewSearchProduct
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchCodeProductTest()
        {
            string searchProduct = "2023"; // TODO: Initialize to an appropriate value
            string expected = "Jeringa"; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadDataGridViewSearchBuyProduct(searchProduct);
            Assert.AreEqual(expected, actual.Rows[0]["NameProduct"].ToString());
        }
        /// <summary>
        ///A test for GroupProduct LoadDataGridViewSearchProduct
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchGroupProductTest()
        {
            string searchProduct = "Anestesia"; // TODO: Initialize to an appropriate value
            string expected = "Jeringa"; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadProduct(searchProduct);
            Assert.AreEqual(expected, actual.Rows[0]["NameProduct"].ToString());
        }
        /// <summary>
        ///A test for NameProduct LoadDataGridViewSearchProduct
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchNameProductTest()
        {
            string searchProduct = "100"; // TODO: Initialize to an appropriate value
            string expected = "Jeringa para ñinos"; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadDataGridViewSearchBuyProduct(searchProduct);
            Assert.AreEqual(expected, actual.Rows[0]["Description"].ToString());
        }
        /// <summary>
        ///A test for Null LoadDataGridViewSearchProduct
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchNullProductTest()
        {
            string searchProduct = "alcohol"; // TODO: Initialize to an appropriate value
            string expected = null; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = ProductManager.LoadDataGridViewSearchBuyProduct(searchProduct);
            Assert.AreEqual(expected, actual);
        }
    }
}
